package com.xoa.dev.pz.controller;

import com.xoa.dev.pz.model.PzCorrection;
import com.xoa.dev.pz.model.PzCorrectionWithBLOBs;
import com.xoa.dev.pz.service.impl.PzCorrectionService;
import com.xoa.util.ToJson;
import org.springframework.beans.propertyeditors.CustomDateEditor;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.WebDataBinder;
import org.springframework.web.bind.annotation.InitBinder;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * Created by 李显 on 2017/12/2.
 * 社区矫正表
 */
@Controller
@RequestMapping("/pzCorrection")
public class PzCorrectionController {

    @InitBinder
    public void initBinder(WebDataBinder binder) {
        SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
        dateFormat.setLenient(false);
        binder.registerCustomEditor(Date.class, new CustomDateEditor(dateFormat, true));   //true:允许输入空值，false:不能为空值
    }

    @Resource
    private PzCorrectionService pzCorrectionService;

    @RequestMapping("/pzCorrectionManager")
    public String pzCorrectionManager(HttpServletRequest request) {
        return "app/pz/pzCorretion/pzCorrectionManager";
    }

    @RequestMapping("/ShjzryProInfo")
    public String ShjzryProInfo(HttpServletRequest request) {
        return "app/pzGrid/gridShjzryProInfo";
    }
    @RequestMapping("/ShjzryInfo")
    public String ShjzryInfo(HttpServletRequest request) {
        return "app/pzGrid/gridShjzryInfo";
    }
    /**
     * 创建作者:   李显
     * 创建日期:   2017年12月2日 12:53:30
     * 方法介绍:   添加社区矫正人员
     * 参数说明:
     * 返回值说明:
     */
    @RequestMapping("/insertSelective")
    @ResponseBody
    public ToJson<PzCorrectionWithBLOBs> insertSelective(HttpServletRequest request, PzCorrectionWithBLOBs record){
        return pzCorrectionService.insertSelective(request,record);
    }
    /**
     * 创建作者:   李显
     * 创建日期:   2017年12月2日 12:53:30
     * 方法介绍:   修改社区矫正人员
     * 参数说明:
     * 返回值说明:
     */
    @RequestMapping("/updateByPrimaryKeySelective")
    @ResponseBody
    public ToJson<PzCorrectionWithBLOBs> updateByPrimaryKeySelective (HttpServletRequest request, PzCorrectionWithBLOBs record){
        ToJson<PzCorrectionWithBLOBs> json = pzCorrectionService.updateByPrimaryKeySelective(request,record);
        return json;
    }
    /**
     * 创建作者:   李显
     * 创建日期:   2017年12月2日 12:53:30
     * 方法介绍:   删除社区矫正人员
     * 参数说明:
     * 返回值说明:
     */
    @RequestMapping("/deleteByPrimaryKey")
    @ResponseBody
    public ToJson<PzCorrectionWithBLOBs> deleteByPrimaryKey(HttpServletRequest request, int correctionId){
        return pzCorrectionService.deleteByPrimaryKey(request,correctionId);
    }
    /**
     * 创建作者:   李显
     * 创建日期:   2017年12月2日 12:53:30
     * 方法介绍:   查询社区矫正人员
     * 参数说明:
     * 返回值说明:
     */
    @RequestMapping("/queryPzCorrection")
    @ResponseBody

    public ToJson<PzCorrectionWithBLOBs> queryPzCorrection(PzCorrectionWithBLOBs pzCorrectionWithBLOBs, Integer page, Integer pageSize, boolean useFlag, String output, HttpServletRequest request, HttpServletResponse response){
        return pzCorrectionService.queryPzCorrection(pzCorrectionWithBLOBs, page, pageSize, useFlag,output,request,response);
    }


    /**
     * 张丽军：导出
     * @param pzCorrection
     * @param page
     * @param pageSize
     * @param useFlag
     * @param request
     * @param response
     * @return
     */
    @RequestMapping("/queryAll")
    @ResponseBody
    public ToJson<PzCorrectionWithBLOBs> queryAll(PzCorrection pzCorrection, Integer page, Integer pageSize, boolean useFlag, HttpServletRequest request, HttpServletResponse response, String export, String pCradId, String pName){
        return pzCorrectionService.queryAll(pzCorrection, page, pageSize, useFlag,request,response,export,pCradId,pName);
    }

    /**
     * 创建作者:   李显
     * 创建日期:   2017年12月2日 12:53:30
     * 方法介绍:   社区矫正人员详情
     * 参数说明:
     * 返回值说明:
     */
    @RequestMapping("/selectById")
    @ResponseBody
    public ToJson<PzCorrectionWithBLOBs> selectById(int correctionId, HttpServletRequest request){
        return pzCorrectionService.selectById(correctionId,request);
    }

    @RequestMapping("/import")
    @ResponseBody
    public ToJson<PzCorrectionWithBLOBs> inputFixAsserts(HttpServletRequest request, HttpServletResponse response, MultipartFile file, HttpSession session){
        return pzCorrectionService.inputFixAsserts(request,response,file,session);
    }

    /**
     * 张丽军：导入接口
     */
    @RequestMapping("/importCorrection")
    @ResponseBody
    public ToJson<PzCorrectionWithBLOBs> importCorrection(HttpServletRequest request, HttpServletResponse response, MultipartFile file, HttpSession session){
        return pzCorrectionService.importCorrection(request,response,file,session);
    }
}
